In recent years, various terminals with functions such as audio recording and video recording are more and more widely adopted, and user requirements for storage space of the terminals increasingly grow.
FIG. 1 is a schematic view of a storage format of a media file in the prior art, in which the media file is composed of a file header, media data, and a media index. The file header records some basic information of the media file, such as the title, producer, encoding format, and encoding rate. The encoded media data is written as chunks in the file at intervals, where each chunk represents media data within a fixed unit time (usually, 1 s). After the media data is written, an encoding program generates a media index according to the situation of writing the chunks and writes media index information to a tail of the file. The media index records information such as a storage location of each media chunk and the size of the chunk, and is an important portion for ensuring that the media file can be played normally.
The media index information is generated and saved once after the media data is written. Therefore, in order to ensure that the media index information can be saved correctly in limited storage space, before the terminal records the media, a time during which the recording is allowed is predicted according to the current available storage space. The specific prediction method is as follows: The size of the current available storage space of the terminal S is obtained (in byte, Kbyte, or Mbyte); a media encoding rate (in bit/s) is converted to storage space V required to be occupied by the media data within a unit time (in byte/s); and a maximum time T during which the media recording is allowed can be obtained by calculating S/V. During the media recording process, if the current continuous recording time reaches a threshold slightly smaller than T, the terminal automatically stops the recording operation, then generates the media index, and writes the media index to the tail of the recorded media file.
In the implementation of the present invention, the inventor finds that the prior art at least has the following problems.
For a terminal system supporting multiple tasks, other types of data writing tasks such as data downloading may be carried out during the media recording process. In this case, the change rate of the storage space may exceed expectation. If the storage space is already used up before the recording time reaches the predicted threshold, the media index information fails to be written, and the media data written earlier cannot be played normally, resulting in bad user experience.